<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>S110_nRF51822/Board/nrf6310_nrf2752/ble/ble_app_proximity/main.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css" />
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="alias.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="alias.js"></script>

<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>


<script type="text/javascript">
  jQuery(document).ready(function () {
    if(gref){ // Number all _img and _table classes
      gref();
    }
  });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->

<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">nRF51822 BLE SDK
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('nrf6310__nrf2752_2ble_2ble__app__proximity_2main_8c.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">S110_nRF51822/Board/nrf6310_nrf2752/ble/ble_app_proximity/main.c</div>  </div>
</div>
<div class="contents">
<a href="nrf6310__nrf2752_2ble_2ble__app__proximity_2main_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.</span>
<a name="l00002"></a>00002 <span class="comment"> *</span>
<a name="l00003"></a>00003 <span class="comment"> * The information contained herein is confidential property of Nordic</span>
<a name="l00004"></a>00004 <span class="comment"> * Semiconductor ASA.Terms and conditions of usage are described in detail</span>
<a name="l00005"></a>00005 <span class="comment"> * in NORDIC SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.</span>
<a name="l00006"></a>00006 <span class="comment"> *</span>
<a name="l00007"></a>00007 <span class="comment"> * Licensees are granted free, non-transferable use of the information. NO</span>
<a name="l00008"></a>00008 <span class="comment"> * WARRANTY of ANY KIND is provided. This heading must NOT be removed from</span>
<a name="l00009"></a>00009 <span class="comment"> * the file.</span>
<a name="l00010"></a>00010 <span class="comment"> *</span>
<a name="l00011"></a>00011 <span class="comment"> * $$</span>
<a name="l00012"></a>00012 <span class="comment"> */</span>
<a name="l00013"></a>00013 
<a name="l00030"></a>00030 <span class="preprocessor">#include &lt;stdint.h&gt;</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00032"></a>00032 <span class="preprocessor">#include &quot;<a class="code" href="nordic__common_8h.html" title="Common defines and macros for firmware developed by Nordic Semiconductor.">nordic_common.h</a>&quot;</span>
<a name="l00033"></a>00033 <span class="preprocessor">#include &quot;nrf.h&quot;</span>
<a name="l00034"></a>00034 <span class="preprocessor">#include &quot;<a class="code" href="nrf__assert_8h.html" title="Utilities for verifying program logic.">nrf_assert.h</a>&quot;</span>
<a name="l00035"></a>00035 <span class="preprocessor">#include &quot;nrf_error.h&quot;</span>
<a name="l00036"></a>00036 <span class="preprocessor">#include &quot;nrf_gpio.h&quot;</span>
<a name="l00037"></a>00037 <span class="preprocessor">#include &quot;nrf51_bitfields.h&quot;</span>
<a name="l00038"></a>00038 <span class="preprocessor">#include &quot;ble.h&quot;</span>
<a name="l00039"></a>00039 <span class="preprocessor">#include &quot;<a class="code" href="ble__srv__common_8h.html">ble_srv_common.h</a>&quot;</span>
<a name="l00040"></a>00040 <span class="preprocessor">#include &quot;<a class="code" href="ble__advdata_8h.html">ble_advdata.h</a>&quot;</span>
<a name="l00041"></a>00041 <span class="preprocessor">#include &quot;<a class="code" href="ble__tps_8h.html">ble_tps.h</a>&quot;</span>
<a name="l00042"></a>00042 <span class="preprocessor">#include &quot;<a class="code" href="ble__ias_8h.html">ble_ias.h</a>&quot;</span>
<a name="l00043"></a>00043 <span class="preprocessor">#include &quot;<a class="code" href="ble__lls_8h.html">ble_lls.h</a>&quot;</span>
<a name="l00044"></a>00044 <span class="preprocessor">#include &quot;<a class="code" href="ble__bas_8h.html">ble_bas.h</a>&quot;</span>
<a name="l00045"></a>00045 <span class="preprocessor">#include &quot;<a class="code" href="ble__conn__params_8h.html">ble_conn_params.h</a>&quot;</span>
<a name="l00046"></a>00046 <span class="preprocessor">#include &quot;<a class="code" href="ble__nrf6310__pins_8h.html">ble_nrf6310_pins.h</a>&quot;</span>
<a name="l00047"></a>00047 <span class="preprocessor">#include &quot;<a class="code" href="ble__sensorsim_8h.html">ble_sensorsim.h</a>&quot;</span>
<a name="l00048"></a>00048 <span class="preprocessor">#include &quot;<a class="code" href="ble__stack__handler_8h.html">ble_stack_handler.h</a>&quot;</span>
<a name="l00049"></a>00049 <span class="preprocessor">#include &quot;<a class="code" href="app__timer_8h.html">app_timer.h</a>&quot;</span>
<a name="l00050"></a>00050 <span class="preprocessor">#include &quot;<a class="code" href="ble__bondmngr_8h.html">ble_bondmngr.h</a>&quot;</span>
<a name="l00051"></a>00051 
<a name="l00052"></a>00052 
<a name="l00053"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#gabab92753edef69fc4821618765ae1541">00053</a> <span class="preprocessor">#define ALERT_LEVEL_MILD_LED_PIN_NO     NRF6310_LED_2                  </span>
<a name="l00054"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga40c245aa7d948f577a38078b5fc7fa84">00054</a> <span class="preprocessor">#define ALERT_LEVEL_HIGH_LED_PIN_NO     NRF6310_LED_3                  </span>
<a name="l00055"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga70b0e83bb09a339ead4165071e8121ae">00055</a> <span class="preprocessor">#define ADV_INTERVAL_SLOW_LED_PIN_NO    NRF6310_LED_4                  </span>
<a name="l00057"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga5f5a2c9450ebc584b4fe743c6b1a280b">00057</a> <span class="preprocessor">#define DEVICE_NAME                     &quot;PRX_APPV0.1&quot;                  </span>
<a name="l00058"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga5af0eca94bfe9c08e0f0afe7d1e135c3">00058</a> <span class="preprocessor">#define APP_ADV_INTERVAL_FAST           0x0028                         </span>
<a name="l00059"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#gab8e8444f5d93426322d8cc2778d5fcf0">00059</a> <span class="preprocessor">#define APP_ADV_INTERVAL_SLOW           0x0C80                         </span>
<a name="l00060"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#gaf58371bad8e1be8e2323df60379ed2df">00060</a> <span class="preprocessor">#define APP_ADV_TIMEOUT_IN_SECONDS      180                            </span>
<a name="l00061"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#gab4de9cc4edfce504a560aa7bcb2c7cd3">00061</a> <span class="preprocessor">#define ADV_INTERVAL_FAST_PERIOD        30000                          </span>
<a name="l00063"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#gaf28f0232a3fdc0eb03b94eb34b25cde8">00063</a> <span class="preprocessor">#define BATTERY_LEVEL_MEAS_INTERVAL     2000                           </span>
<a name="l00064"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga59eb06cba38be11278ebd2829e95bc26">00064</a> <span class="preprocessor">#define MIN_BATTERY_LEVEL               81                             </span>
<a name="l00065"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga16896fb7a69ca90a4a4e341d5a888002">00065</a> <span class="preprocessor">#define MAX_BATTERY_LEVEL               100                            </span>
<a name="l00066"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga69eef02165834e4dabc5757b82dddbf1">00066</a> <span class="preprocessor">#define BATTERY_LEVEL_INCREMENT         1                              </span>
<a name="l00068"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga95196d5d0f40cf195a6001955d6d98cf">00068</a> <span class="preprocessor">#define MIN_CONN_INTERVAL               ((1 * 800) / 2)                </span>
<a name="l00069"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga7d868ed8adb7d475b463fd8855907a18">00069</a> <span class="preprocessor">#define MAX_CONN_INTERVAL               (1 * 800)                      </span>
<a name="l00070"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga0c921a874ac37870fc1516ce66cd228a">00070</a> <span class="preprocessor">#define SLAVE_LATENCY                   0                              </span>
<a name="l00071"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga799412c2b531ca347e13611e6e7523b9">00071</a> <span class="preprocessor">#define CONN_SUP_TIMEOUT                (4 * 100)                      </span>
<a name="l00072"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga7204f7a367e8f1ac53ef62c4ad220efc">00072</a> <span class="preprocessor">#define FIRST_CONN_PARAMS_UPDATE_DELAY  (20 * 1000)                    </span>
<a name="l00073"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#gadf85796ef07632ed27e0bce9509d9245">00073</a> <span class="preprocessor">#define NEXT_CONN_PARAMS_UPDATE_DELAY   (5 * 1000)                     </span>
<a name="l00074"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga34db81384bfbef23dedbef9bc6dfe46c">00074</a> <span class="preprocessor">#define MAX_CONN_PARAMS_UPDATE_COUNT    3                              </span>
<a name="l00076"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga7c1fffb0f865552108560d4c63b32db1">00076</a> <span class="preprocessor">#define SEC_PARAM_TIMEOUT               60                             </span>
<a name="l00077"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#gacbf03a82593c273743a5a80a1119b851">00077</a> <span class="preprocessor">#define SEC_PARAM_BOND                  1                              </span>
<a name="l00078"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#gab6831ebe113f8afe970326b7742b5947">00078</a> <span class="preprocessor">#define SEC_PARAM_MITM                  0                              </span>
<a name="l00079"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga42df85b3a4083cdc614d9111d580d98f">00079</a> <span class="preprocessor">#define SEC_PARAM_IO_CAPABILITIES       BLE_GAP_IO_CAPS_NONE           </span>
<a name="l00080"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#gaee13a0d0077f423fa0edd74e17fb6b88">00080</a> <span class="preprocessor">#define SEC_PARAM_OOB                   0                              </span>
<a name="l00081"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga6b7b2e2f67fbf790f55b46f8f5e24ad5">00081</a> <span class="preprocessor">#define SEC_PARAM_MIN_KEY_SIZE          7                              </span>
<a name="l00082"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#gaf2cd1595de153ea1d6d843619a1a7707">00082</a> <span class="preprocessor">#define SEC_PARAM_MAX_KEY_SIZE          16                             </span>
<a name="l00084"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga6c90d462c21d0b30c272f5cba8963836">00084</a> <span class="preprocessor">#define INITIAL_LLS_ALERT_LEVEL         BLE_CHAR_ALERT_LEVEL_NO_ALERT  </span>
<a name="l00085"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga5273cd1f329a5864a9c2bd28f65e9d54">00085</a> <span class="preprocessor">#define TX_POWER_LEVEL                  (-8)                           </span>
<a name="l00087"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#gafd5babfaabd7e4c921c4cc813fb3f31f">00087</a> <span class="preprocessor">static ble_tps_t                        s_tps;                         </span>
<a name="l00088"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga7ae2ab02279a8b58ff472c6d050bbe60">00088</a> <span class="preprocessor">static ble_ias_t                        s_ias;                         </span>
<a name="l00089"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#gab81d1349f60eface9bdcf27d9ece74a5">00089</a> <span class="preprocessor">static ble_lls_t                        s_lls;                         </span>
<a name="l00090"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#gab22f840926bbada5a0ba32f2f7dc94b3">00090</a> <span class="preprocessor">static ble_bas_t                        s_bas;                         </span>
<a name="l00091"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga738ed84e141ba1059dd1318dc425343c">00091</a> <span class="preprocessor">static ble_gap_sec_params_t             s_sec_params;                  </span>
<a name="l00092"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga76b78faf2670ecd8a7deea500be9d971">00092</a> <span class="preprocessor">static bool                             s_is_advertising = false;      </span>
<a name="l00094"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#gaa752585d9b405d6e0c6fd392d7f64b59">00094</a> <span class="preprocessor">static ble_sensorsim_cfg_t              s_battery_sim_cfg;             </span>
<a name="l00095"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#gaa51f5fc284e1b7e1570ab742fa9b63f3">00095</a> <span class="preprocessor">static ble_sensorsim_state_t            s_battery_sim_state;           </span>
<a name="l00098"></a>00098 <span class="preprocessor">static void on_ias_evt(ble_ias_t * p_ias, ble_ias_evt_t * p_evt);</span>
<a name="l00099"></a>00099 <span class="preprocessor"></span><span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__proximity__main.html#ga038703ec77748ff3b1b0c88f21579c5c" title="Link Loss event handler.">on_lls_evt</a>(<a class="code" href="structble__lls__s.html" title="Link Loss Service structure. This contains various status information for the service.">ble_lls_t</a> * p_lls, <a class="code" href="structble__lls__evt__t.html" title="Link Loss Service event.">ble_lls_evt_t</a> * p_evt);
<a name="l00100"></a>00100 <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__proximity__main.html#ga236a1a602913d6780d797d929507873e" title="Start advertising.">advertising_start</a>(<span class="keywordtype">bool</span> fast_advertising);
<a name="l00101"></a>00101 
<a name="l00102"></a>00102 
<a name="l00110"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#gadec561788a76b8a63ad9663625a25d78">00110</a> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__gzll__main.html#gadec561788a76b8a63ad9663625a25d78" title="Assert macro callback function.">assert_nrf_callback</a>(uint16_t line_num, <span class="keyword">const</span> uint8_t * file_name)
<a name="l00111"></a>00111 {
<a name="l00112"></a>00112     <span class="comment">// Copying parameters to static variables because parameters are not accessible in debugger</span>
<a name="l00113"></a>00113     <span class="keyword">static</span> <span class="keyword">volatile</span> uint8_t  s_file_name[128];
<a name="l00114"></a>00114     <span class="keyword">static</span> <span class="keyword">volatile</span> uint16_t s_line_num;
<a name="l00115"></a>00115 
<a name="l00116"></a>00116     strcpy((<span class="keywordtype">char</span> *)s_file_name, (<span class="keyword">const</span> <span class="keywordtype">char</span> *)file_name);
<a name="l00117"></a>00117     s_line_num = line_num;
<a name="l00118"></a>00118     UNUSED_VARIABLE(s_file_name);
<a name="l00119"></a>00119     UNUSED_VARIABLE(s_line_num);
<a name="l00120"></a>00120     
<a name="l00121"></a>00121     <a class="code" href="group__nrf__gpio.html#gacaf7e8e242a47f7b635bbeca5c5934a3" title="Set GPIO pin.">nrf_gpio_pin_set</a>(ASSERT_LED_PIN_NO);
<a name="l00122"></a>00122 
<a name="l00123"></a>00123     <span class="keywordflow">for</span> (;;)
<a name="l00124"></a>00124     {
<a name="l00125"></a>00125         <span class="comment">// Loop forever. On assert, the system can only recover on reset</span>
<a name="l00126"></a>00126     }
<a name="l00127"></a>00127 }
<a name="l00128"></a>00128 
<a name="l00129"></a>00129 
<a name="l00137"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga54ab546c90d69e5fc9cfee653024ea53">00137</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__proximity__main.html#ga54ab546c90d69e5fc9cfee653024ea53" title="Service error handler.">service_error_handler</a>(uint32_t nrf_error)
<a name="l00138"></a>00138 {
<a name="l00139"></a>00139     <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00140"></a>00140 }
<a name="l00141"></a>00141 
<a name="l00142"></a>00142 
<a name="l00149"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#gaf58c137ee11618425f8f0fa165834428">00149</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__proximity__main.html#gaf58c137ee11618425f8f0fa165834428" title="Advertising Interval Change timer timeout handler.">adv_interval_change_timeout_handler</a>(app_timer_id_t timer_id)
<a name="l00150"></a>00150 {
<a name="l00151"></a>00151     <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(timer_id == APP_TIMER_ADV_INTERVAL_CHANGE);
<a name="l00152"></a>00152     <a class="code" href="group__ble__sdk__app__proximity__main.html#ga236a1a602913d6780d797d929507873e" title="Start advertising.">advertising_start</a>(<span class="keyword">false</span>);
<a name="l00153"></a>00153 }
<a name="l00154"></a>00154 
<a name="l00155"></a>00155 
<a name="l00158"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga236a1a602913d6780d797d929507873e">00158</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__proximity__main.html#ga236a1a602913d6780d797d929507873e" title="Start advertising.">advertising_start</a>(<span class="keywordtype">bool</span> fast_advertising)
<a name="l00159"></a>00159 {
<a name="l00160"></a>00160     uint32_t             err_code;
<a name="l00161"></a>00161     <a class="code" href="structble__gap__adv__params__t.html" title="GAP advertising parameters.">ble_gap_adv_params_t</a> adv_params;
<a name="l00162"></a>00162     
<a name="l00163"></a>00163     <span class="comment">// If we are already advertising, stop it</span>
<a name="l00164"></a>00164     <span class="keywordflow">if</span> (<a class="code" href="group__ble__sdk__app__proximity__main.html#ga76b78faf2670ecd8a7deea500be9d971">s_is_advertising</a>)
<a name="l00165"></a>00165     {
<a name="l00166"></a>00166         err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga9c37d82f7855abd7417010d8a04c9718" title="Stop advertising (GAP Discoverable, Connectable modes, Broadcast Procedure).">ble_gap_adv_stop</a>();
<a name="l00167"></a>00167         <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00168"></a>00168         {
<a name="l00169"></a>00169             <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00170"></a>00170         }
<a name="l00171"></a>00171     }
<a name="l00172"></a>00172 
<a name="l00173"></a>00173     <span class="comment">// Start advertising</span>
<a name="l00174"></a>00174     memset(&amp;adv_params, 0, <span class="keyword">sizeof</span>(adv_params));
<a name="l00175"></a>00175     
<a name="l00176"></a>00176     adv_params.<a class="code" href="structble__gap__adv__params__t.html#a1d127017fb298b889f4ba24752d08b8e">type</a>        = <a class="code" href="group___b_l_e___g_a_p___a_d_v___t_y_p_e_s.html#ga6cc0db53453977ee0a31e59f07de2b86">BLE_GAP_ADV_TYPE_ADV_IND</a>;
<a name="l00177"></a>00177     adv_params.<a class="code" href="structble__gap__adv__params__t.html#a27909d1b865548f236a871af2b6aa584">p_peer_addr</a> = NULL;
<a name="l00178"></a>00178     adv_params.<a class="code" href="structble__gap__adv__params__t.html#aefdab55ee0f22565a03a14d09cc71d12">fp</a>          = <a class="code" href="group___b_l_e___g_a_p___a_d_v___f_i_l_t_e_r___p_o_l_i_c_i_e_s.html#ga0b0393df73db101d6cbfaede2dbb7ea6">BLE_GAP_ADV_FP_ANY</a>;
<a name="l00179"></a>00179     adv_params.<a class="code" href="structble__gap__adv__params__t.html#a6c52a3d605c056768b59164ce8df8334">interval</a>    = (fast_advertising) ? <a class="code" href="group__ble__sdk__app__proximity__main.html#ga5af0eca94bfe9c08e0f0afe7d1e135c3">APP_ADV_INTERVAL_FAST</a> : <a class="code" href="group__ble__sdk__app__proximity__main.html#gab8e8444f5d93426322d8cc2778d5fcf0">APP_ADV_INTERVAL_SLOW</a>;
<a name="l00180"></a>00180     adv_params.<a class="code" href="structble__gap__adv__params__t.html#a7f1ad43d3bf79b40bc39dbb5a6c3a5ae">timeout</a>     = <a class="code" href="group__ble__sdk__app__proximity__main.html#gaf58371bad8e1be8e2323df60379ed2df">APP_ADV_TIMEOUT_IN_SECONDS</a>;
<a name="l00181"></a>00181 
<a name="l00182"></a>00182     err_code = <a class="code" href="group___b_l_e___g_a_p.html#gabdbf78c3a8b09c6f2fb92d8733096af8" title="Start advertising (GAP Discoverable, Connectable modes, Broadcast Procedure).">ble_gap_adv_start</a>(&amp;adv_params);
<a name="l00183"></a>00183     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00184"></a>00184     {
<a name="l00185"></a>00185         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00186"></a>00186     }
<a name="l00187"></a>00187     <a class="code" href="group__ble__sdk__app__proximity__main.html#ga76b78faf2670ecd8a7deea500be9d971">s_is_advertising</a> = <span class="keyword">true</span>;
<a name="l00188"></a>00188     
<a name="l00189"></a>00189     <a class="code" href="group__nrf__gpio.html#gacaf7e8e242a47f7b635bbeca5c5934a3" title="Set GPIO pin.">nrf_gpio_pin_set</a>(ADVERTISING_LED_PIN_NO);
<a name="l00190"></a>00190     <a class="code" href="group__nrf__gpio.html#ga7fefa8a71e25eeb57b5b4230b0dd0484" title="Write value to GPIO pin.">nrf_gpio_pin_write</a>(<a class="code" href="group__ble__sdk__app__proximity__main.html#ga70b0e83bb09a339ead4165071e8121ae">ADV_INTERVAL_SLOW_LED_PIN_NO</a>, !fast_advertising);
<a name="l00191"></a>00191     
<a name="l00192"></a>00192     <span class="comment">// If we are starting fast advertising, start timer for switching to slow advertising</span>
<a name="l00193"></a>00193     <span class="keywordflow">if</span> (fast_advertising)
<a name="l00194"></a>00194     {
<a name="l00195"></a>00195         err_code = <a class="code" href="group__app__timer.html#ga54651d3dc5266bd7541b80918527b060" title="Starts a timer.">app_timer_start</a>(APP_TIMER_ADV_INTERVAL_CHANGE,
<a name="l00196"></a>00196                                    <a class="code" href="group__ble__sdk__app__proximity__main.html#gaf58c137ee11618425f8f0fa165834428" title="Advertising Interval Change timer timeout handler.">adv_interval_change_timeout_handler</a>,
<a name="l00197"></a>00197                                    <a class="code" href="group__ble__sdk__app__proximity__main.html#gab4de9cc4edfce504a560aa7bcb2c7cd3">ADV_INTERVAL_FAST_PERIOD</a>,
<a name="l00198"></a>00198                                    APP_TIMER_MODE_SINGLE_SHOT,
<a name="l00199"></a>00199                                    <a class="code" href="group__app__timer.html#ga02ba0b12340bf53b472283b752257f06">APP_TIMER_LOWEST_PRI</a>);
<a name="l00200"></a>00200         <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00201"></a>00201         {
<a name="l00202"></a>00202             <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00203"></a>00203         }
<a name="l00204"></a>00204     }
<a name="l00205"></a>00205 }
<a name="l00206"></a>00206 
<a name="l00207"></a>00207 
<a name="l00210"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#gab155022684d4acfd98218c3799822e74">00210</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__proximity__main.html#gab155022684d4acfd98218c3799822e74" title="Perform battery measurement, and update Battery Level characteristic in Battery Service.">battery_level_update</a>(<span class="keywordtype">void</span>)
<a name="l00211"></a>00211 {
<a name="l00212"></a>00212     uint32_t err_code;
<a name="l00213"></a>00213     uint8_t  battery_level;
<a name="l00214"></a>00214     
<a name="l00215"></a>00215     battery_level = (uint8_t)<a class="code" href="group__ble__sdk__lib__sensorsim.html#gae73b8f0f956e0708e16d160605318ba8" title="Generate a simulated sensor measurement using a triangular waveform generator.">ble_sensorsim_measure</a>(&amp;<a class="code" href="group__ble__sdk__app__proximity__main.html#gaa51f5fc284e1b7e1570ab742fa9b63f3">s_battery_sim_state</a>, &amp;<a class="code" href="group__ble__sdk__app__proximity__main.html#gaa752585d9b405d6e0c6fd392d7f64b59">s_battery_sim_cfg</a>);
<a name="l00216"></a>00216     
<a name="l00217"></a>00217     err_code = <a class="code" href="group__ble__sdk__srv__bas.html#ga58d8f4336cce49ea5b3a2f8997bfe00e" title="Update battery level.">ble_bas_battery_level_update</a>(&amp;<a class="code" href="group__ble__sdk__app__proximity__main.html#gab22f840926bbada5a0ba32f2f7dc94b3">s_bas</a>, battery_level);
<a name="l00218"></a>00218     <span class="keywordflow">if</span> (
<a name="l00219"></a>00219         (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00220"></a>00220         &amp;&amp;
<a name="l00221"></a>00221         (err_code != <a class="code" href="group__nrf__error.html#gaf0aff2ba7864b34a36b4a96986e1851e" title="Invalid state, operation disallowed in this state.">NRF_ERROR_INVALID_STATE</a>)
<a name="l00222"></a>00222         &amp;&amp;
<a name="l00223"></a>00223         (err_code != <a class="code" href="group__ble__err.html#ga901e1bc3ccae29eff9fb31cabdbb5e02">BLE_ERROR_NO_TX_BUFFERS</a>)
<a name="l00224"></a>00224         &amp;&amp;
<a name="l00225"></a>00225         (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
<a name="l00226"></a>00226     )
<a name="l00227"></a>00227     {
<a name="l00228"></a>00228         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00229"></a>00229     }
<a name="l00230"></a>00230 }
<a name="l00231"></a>00231 
<a name="l00232"></a>00232 
<a name="l00239"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga7e5b3d2cf024dde83b8c536b22a1c155">00239</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__proximity__main.html#ga7e5b3d2cf024dde83b8c536b22a1c155" title="Battery measurement timer timeout handler.">battery_level_meas_timeout_handler</a>(app_timer_id_t timer_id)
<a name="l00240"></a>00240 {
<a name="l00241"></a>00241     <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(timer_id == APP_TIMER_BATTERY_LEVEL_MEAS);
<a name="l00242"></a>00242     <a class="code" href="group__ble__sdk__app__proximity__main.html#gab155022684d4acfd98218c3799822e74" title="Perform battery measurement, and update Battery Level characteristic in Battery Service.">battery_level_update</a>();
<a name="l00243"></a>00243 }
<a name="l00244"></a>00244 
<a name="l00245"></a>00245 
<a name="l00250"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga0892e076b365fc49b55bd0f90ab09222">00250</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__gzll__ui.html#ga67cfc3137a465e560792490e81365254" title="LEDs initialization.">leds_init</a>(<span class="keywordtype">void</span>)
<a name="l00251"></a>00251 {
<a name="l00252"></a>00252     <a class="code" href="group__ble__sdk__lib__util.html#ga3f8d3d1b629cf9a61a86886059987e6a" title="Configure a PIN to be used as a LED.">GPIO_LED_CONFIG</a>(ADVERTISING_LED_PIN_NO);
<a name="l00253"></a>00253     <a class="code" href="group__ble__sdk__lib__util.html#ga3f8d3d1b629cf9a61a86886059987e6a" title="Configure a PIN to be used as a LED.">GPIO_LED_CONFIG</a>(CONNECTED_LED_PIN_NO);
<a name="l00254"></a>00254     <a class="code" href="group__ble__sdk__lib__util.html#ga3f8d3d1b629cf9a61a86886059987e6a" title="Configure a PIN to be used as a LED.">GPIO_LED_CONFIG</a>(ASSERT_LED_PIN_NO);
<a name="l00255"></a>00255     
<a name="l00256"></a>00256     <a class="code" href="group__ble__sdk__lib__util.html#ga3f8d3d1b629cf9a61a86886059987e6a" title="Configure a PIN to be used as a LED.">GPIO_LED_CONFIG</a>(<a class="code" href="group__ble__sdk__app__proximity__main.html#gabab92753edef69fc4821618765ae1541">ALERT_LEVEL_MILD_LED_PIN_NO</a>);
<a name="l00257"></a>00257     <a class="code" href="group__ble__sdk__lib__util.html#ga3f8d3d1b629cf9a61a86886059987e6a" title="Configure a PIN to be used as a LED.">GPIO_LED_CONFIG</a>(<a class="code" href="group__ble__sdk__app__proximity__main.html#ga40c245aa7d948f577a38078b5fc7fa84">ALERT_LEVEL_HIGH_LED_PIN_NO</a>);
<a name="l00258"></a>00258     <a class="code" href="group__ble__sdk__lib__util.html#ga3f8d3d1b629cf9a61a86886059987e6a" title="Configure a PIN to be used as a LED.">GPIO_LED_CONFIG</a>(<a class="code" href="group__ble__sdk__app__proximity__main.html#ga70b0e83bb09a339ead4165071e8121ae">ADV_INTERVAL_SLOW_LED_PIN_NO</a>);
<a name="l00259"></a>00259 }
<a name="l00260"></a>00260 
<a name="l00261"></a>00261 
<a name="l00264"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga265c25c068555fbfae4ab4f391060040">00264</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__gzll__ui.html#gacef6dd444cb6560da652897ee43ab306" title="Initialize GPIOTE module for detecting buttons.">buttons_init</a>(<span class="keywordtype">void</span>)
<a name="l00265"></a>00265 {
<a name="l00266"></a>00266     <span class="comment">// Set Button 0 as wakeup source</span>
<a name="l00267"></a>00267     <a class="code" href="group__ble__sdk__lib__util.html#ga6259b9f2ea4ab48312b1836c71f484bb" title="Macro to configure an I/O.">GPIO_PIN_CONFIG</a>(NRF6310_BUTTON_0, 
<a name="l00268"></a>00268                     GPIO_PIN_CNF_DIR_Input, 
<a name="l00269"></a>00269                     GPIO_PIN_CNF_PULL_Disabled, 
<a name="l00270"></a>00270                     GPIO_PIN_CNF_DRIVE_S0S1, 
<a name="l00271"></a>00271                     GPIO_PIN_CNF_SENSE_Low);
<a name="l00272"></a>00272                     
<a name="l00273"></a>00273     <span class="comment">// Set Button 1 as wakeup source</span>
<a name="l00274"></a>00274     <a class="code" href="group__ble__sdk__lib__util.html#ga6259b9f2ea4ab48312b1836c71f484bb" title="Macro to configure an I/O.">GPIO_PIN_CONFIG</a>(NRF6310_BUTTON_1, 
<a name="l00275"></a>00275                     GPIO_PIN_CNF_DIR_Input, 
<a name="l00276"></a>00276                     GPIO_PIN_CNF_PULL_Disabled, 
<a name="l00277"></a>00277                     GPIO_PIN_CNF_DRIVE_S0S1, 
<a name="l00278"></a>00278                     GPIO_PIN_CNF_SENSE_Low);
<a name="l00279"></a>00279 
<a name="l00280"></a>00280 }
<a name="l00281"></a>00281 
<a name="l00282"></a>00282 
<a name="l00290"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga8014b2b4745214caa69c5fddd0401388">00290</a> <span class="keyword">static</span> __INLINE uint32_t <a class="code" href="group__ble__sdk__app__proximity__main.html#ga8014b2b4745214caa69c5fddd0401388" title="Read the state of the input pin.">gpio_pin_read</a>(uint32_t pin_number)
<a name="l00291"></a>00291 {
<a name="l00292"></a>00292     <span class="keywordflow">return</span>  ((NRF_GPIO-&gt;IN &gt;&gt; pin_number) &amp; 1UL);  
<a name="l00293"></a>00293 }
<a name="l00294"></a>00294 
<a name="l00295"></a>00295 
<a name="l00300"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga09658aaa0774820d8f25249d551bc283">00300</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__proximity__main.html#ga09658aaa0774820d8f25249d551bc283" title="Timer initialization.">timers_init</a>(<span class="keywordtype">void</span>)
<a name="l00301"></a>00301 {
<a name="l00302"></a>00302     uint32_t err_code;
<a name="l00303"></a>00303 
<a name="l00304"></a>00304     <span class="comment">// Initialize timer module</span>
<a name="l00305"></a>00305     err_code = <a class="code" href="group__app__timer.html#ga4e1da5a2f64ee78ee97f7422ea97e439" title="Initializes the timer module.">app_timer_init</a>(NULL);
<a name="l00306"></a>00306     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00307"></a>00307     {
<a name="l00308"></a>00308         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00309"></a>00309     }
<a name="l00310"></a>00310     
<a name="l00311"></a>00311     <span class="comment">// Start battery measurement timer</span>
<a name="l00312"></a>00312     err_code = <a class="code" href="group__app__timer.html#ga54651d3dc5266bd7541b80918527b060" title="Starts a timer.">app_timer_start</a>(APP_TIMER_BATTERY_LEVEL_MEAS, 
<a name="l00313"></a>00313                                <a class="code" href="group__ble__sdk__app__proximity__main.html#ga7e5b3d2cf024dde83b8c536b22a1c155" title="Battery measurement timer timeout handler.">battery_level_meas_timeout_handler</a>, 
<a name="l00314"></a>00314                                <a class="code" href="group__ble__sdk__app__proximity__main.html#gaf28f0232a3fdc0eb03b94eb34b25cde8">BATTERY_LEVEL_MEAS_INTERVAL</a>, 
<a name="l00315"></a>00315                                APP_TIMER_MODE_REPEATED, 
<a name="l00316"></a>00316                                <a class="code" href="group__app__timer.html#ga02ba0b12340bf53b472283b752257f06">APP_TIMER_LOWEST_PRI</a>);
<a name="l00317"></a>00317     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00318"></a>00318     {
<a name="l00319"></a>00319         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00320"></a>00320     }
<a name="l00321"></a>00321 }
<a name="l00322"></a>00322 
<a name="l00323"></a>00323 
<a name="l00329"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga1004973353f351806e42896c491a5ab2">00329</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__proximity__main.html#ga1004973353f351806e42896c491a5ab2" title="GAP initialization.">gap_params_init</a>(<span class="keywordtype">void</span>)
<a name="l00330"></a>00330 {
<a name="l00331"></a>00331     uint32_t                err_code;
<a name="l00332"></a>00332     <a class="code" href="structble__gap__conn__params__t.html" title="GAP connection parameters.">ble_gap_conn_params_t</a>   gap_conn_params;
<a name="l00333"></a>00333     <a class="code" href="structble__gap__conn__sec__mode__t.html" title="GAP link requirements.">ble_gap_conn_sec_mode_t</a> sec_mode;
<a name="l00334"></a>00334 
<a name="l00335"></a>00335     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga2abd1c711d49a4d4b1ab9bf27cafffbb" title="Set sec_mode pointed to by ptr to require no protection, open link.">BLE_GAP_CONN_SEC_MODE_SET_OPEN</a>(&amp;sec_mode);
<a name="l00336"></a>00336     
<a name="l00337"></a>00337     err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga7d665aa56f8d248b8779a6cf170e2052" title="Set GAP device name.">ble_gap_device_name_set</a>(&amp;sec_mode, <a class="code" href="group__ble__sdk__app__proximity__main.html#ga5f5a2c9450ebc584b4fe743c6b1a280b">DEVICE_NAME</a>);
<a name="l00338"></a>00338     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00339"></a>00339     {
<a name="l00340"></a>00340         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00341"></a>00341     }
<a name="l00342"></a>00342 
<a name="l00343"></a>00343     err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga711f129fb97e0071ab04d2e994125f7a" title="Set GAP Appearance field.">ble_gap_appearance_set</a>(<a class="code" href="group___b_l_e___a_p_p_e_a_r_a_n_c_e_s.html#ga7239b3bf480c0814172799d8b52ed478">BLE_APPEARANCE_GENERIC_KEYRING</a>);
<a name="l00344"></a>00344     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00345"></a>00345     {
<a name="l00346"></a>00346         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00347"></a>00347     }
<a name="l00348"></a>00348     
<a name="l00349"></a>00349     memset(&amp;gap_conn_params, 0, <span class="keyword">sizeof</span>(gap_conn_params));
<a name="l00350"></a>00350 
<a name="l00351"></a>00351     gap_conn_params.<a class="code" href="structble__gap__conn__params__t.html#ac927a642ee2203f875fcce1eabb5fa64">min_conn_interval</a> = <a class="code" href="group__ble__sdk__app__proximity__main.html#ga95196d5d0f40cf195a6001955d6d98cf">MIN_CONN_INTERVAL</a>;
<a name="l00352"></a>00352     gap_conn_params.<a class="code" href="structble__gap__conn__params__t.html#a0aec1884f340406a5194b772da017d7b">max_conn_interval</a> = <a class="code" href="group__ble__sdk__app__proximity__main.html#ga7d868ed8adb7d475b463fd8855907a18">MAX_CONN_INTERVAL</a>;
<a name="l00353"></a>00353     gap_conn_params.<a class="code" href="structble__gap__conn__params__t.html#a39219ac00a0e8ed843ee32b9df8be11e">slave_latency</a>     = <a class="code" href="group__ble__sdk__app__proximity__main.html#ga0c921a874ac37870fc1516ce66cd228a">SLAVE_LATENCY</a>;
<a name="l00354"></a>00354     gap_conn_params.<a class="code" href="structble__gap__conn__params__t.html#a2089e7fb26f6b24882d1437eb5553bc7">conn_sup_timeout</a>  = <a class="code" href="group__ble__sdk__app__proximity__main.html#ga799412c2b531ca347e13611e6e7523b9">CONN_SUP_TIMEOUT</a>;
<a name="l00355"></a>00355 
<a name="l00356"></a>00356     err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga28e0062141d77d7b2272fc3a6b6e17c5" title="Set GAP Peripheral Preferred Connection Parameters.">ble_gap_ppcp_set</a>(&amp;gap_conn_params);
<a name="l00357"></a>00357     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00358"></a>00358     {
<a name="l00359"></a>00359         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00360"></a>00360     }
<a name="l00361"></a>00361 
<a name="l00362"></a>00362     err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga99d6ed3853b41dba78dda05a51123986" title="Set the radio&#39;s transmit power.">ble_gap_tx_power_set</a>(<a class="code" href="group__ble__sdk__app__proximity__main.html#ga5273cd1f329a5864a9c2bd28f65e9d54">TX_POWER_LEVEL</a>);
<a name="l00363"></a>00363     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00364"></a>00364     {
<a name="l00365"></a>00365         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00366"></a>00366     }
<a name="l00367"></a>00367 }
<a name="l00368"></a>00368 
<a name="l00369"></a>00369 
<a name="l00375"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga935c9624de0709fe228dbefa4b54de48">00375</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__proximity__main.html#ga935c9624de0709fe228dbefa4b54de48" title="Advertising functionality initialization.">advertising_init</a>(<span class="keywordtype">void</span>)
<a name="l00376"></a>00376 {
<a name="l00377"></a>00377     uint32_t      err_code;
<a name="l00378"></a>00378     <a class="code" href="structble__advdata__t.html" title="Advertising data structure. This contains all options and data needed for encoding and setting the ad...">ble_advdata_t</a> advdata;
<a name="l00379"></a>00379     uint8_t       flags = <a class="code" href="group___b_l_e___g_a_p___d_i_s_c___m_o_d_e_s.html#ga5c5243da93bae524088eefd608656012">BLE_GAP_DISC_MODE_LIMITED</a> | <a class="code" href="group___b_l_e___g_a_p___d_i_s_c___m_o_d_e_s.html#ga346a5b47f4b8f94a08f320a0d8c14c18">BLE_GAP_DISC_BR_EDR_NOT_SUPPORTED</a>;
<a name="l00380"></a>00380     int8_t        tx_power_level = <a class="code" href="group__ble__sdk__app__proximity__main.html#ga5273cd1f329a5864a9c2bd28f65e9d54">TX_POWER_LEVEL</a>;
<a name="l00381"></a>00381     
<a name="l00382"></a>00382     <a class="code" href="structble__uuid__t.html" title="Bluetooth Low Energy UUID type, encapsulates both 16-bit and 128-bit UUIDs.">ble_uuid_t</a> adv_uuids[] = 
<a name="l00383"></a>00383     {
<a name="l00384"></a>00384         {<a class="code" href="group___u_u_i_d___s_e_r_v_i_c_e_s.html#gabe5ff0bce57a32f58a1e16913a38ce04">BLE_UUID_TX_POWER_SERVICE</a>,        <a class="code" href="group___b_l_e___u_u_i_d___t_y_p_e_s.html#gae549d14b15783ba52dae5fdd5f9ac959">BLE_UUID_TYPE_BLE</a>}, 
<a name="l00385"></a>00385         {<a class="code" href="group___u_u_i_d___s_e_r_v_i_c_e_s.html#ga4badeabf171b217259b1f67f554e8064">BLE_UUID_IMMEDIATE_ALERT_SERVICE</a>, <a class="code" href="group___b_l_e___u_u_i_d___t_y_p_e_s.html#gae549d14b15783ba52dae5fdd5f9ac959">BLE_UUID_TYPE_BLE</a>}, 
<a name="l00386"></a>00386         {<a class="code" href="group___u_u_i_d___s_e_r_v_i_c_e_s.html#gabdc9cfe9d896039bef555b0bfe14cbd4">BLE_UUID_LINK_LOSS_SERVICE</a>,       <a class="code" href="group___b_l_e___u_u_i_d___t_y_p_e_s.html#gae549d14b15783ba52dae5fdd5f9ac959">BLE_UUID_TYPE_BLE</a>}
<a name="l00387"></a>00387     };
<a name="l00388"></a>00388 
<a name="l00389"></a>00389     <span class="comment">// Build and set advertising data</span>
<a name="l00390"></a>00390     memset(&amp;advdata, 0, <span class="keyword">sizeof</span>(advdata));
<a name="l00391"></a>00391     
<a name="l00392"></a>00392     advdata.<a class="code" href="structble__advdata__t.html#a045ec5915c094e107ac24d185b83fa49">name_type</a>               = <a class="code" href="group__ble__sdk__lib__advdata.html#gga03c5ccf232779001be9786021b1a563ba63a26e22b9d6a0899edac755d0e2f488">BLE_ADVDATA_FULL_NAME</a>;
<a name="l00393"></a>00393     advdata.<a class="code" href="structble__advdata__t.html#aff2bb3e4016b9a7b6cbcdd6e98feb719">include_appearance</a>      = <span class="keyword">true</span>;
<a name="l00394"></a>00394     advdata.<a class="code" href="structble__advdata__t.html#a3ad6b2c5a983e0f2676c85c546ed47ae">flags</a>.<a class="code" href="structuint8__array__t.html#aaba88b24a21a6c70c895c0d55f4a69a0">size</a>              = <span class="keyword">sizeof</span>(flags);
<a name="l00395"></a>00395     advdata.<a class="code" href="structble__advdata__t.html#a3ad6b2c5a983e0f2676c85c546ed47ae">flags</a>.<a class="code" href="structuint8__array__t.html#a8304c4af5da6e830b86d7199dc9a22e6">p_data</a>            = &amp;flags;
<a name="l00396"></a>00396     advdata.<a class="code" href="structble__advdata__t.html#abf6287e8f903a4896561c23c6b2581ef">p_tx_power_level</a>        = &amp;tx_power_level;
<a name="l00397"></a>00397     advdata.<a class="code" href="structble__advdata__t.html#af848e0d7e7334a53498e1e6c592fed90">uuids_complete</a>.<a class="code" href="structble__advdata__uuid__list__t.html#a1cecc52d144b939f33a67c1d68363e99">uuid_cnt</a> = <span class="keyword">sizeof</span>(adv_uuids) / <span class="keyword">sizeof</span>(adv_uuids[0]);
<a name="l00398"></a>00398     advdata.<a class="code" href="structble__advdata__t.html#af848e0d7e7334a53498e1e6c592fed90">uuids_complete</a>.<a class="code" href="structble__advdata__uuid__list__t.html#a100265d2ed10e66a76e53cba205dc8a3">p_uuids</a>  = adv_uuids;
<a name="l00399"></a>00399     
<a name="l00400"></a>00400     err_code = <a class="code" href="group__ble__sdk__lib__advdata.html#ga180ff4057a0763688c734e98ab8d976b" title="Encodes and sets the advertising data and/or scan response data.">ble_advdata_set</a>(&amp;advdata, NULL);
<a name="l00401"></a>00401     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00402"></a>00402     {
<a name="l00403"></a>00403         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00404"></a>00404     }
<a name="l00405"></a>00405 }
<a name="l00406"></a>00406 
<a name="l00407"></a>00407 
<a name="l00410"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#gab793003188ea0cfe80805f209cfe18f9">00410</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__proximity__main.html#gab793003188ea0cfe80805f209cfe18f9" title="Initialize Tx Power Service.">tps_init</a>(<span class="keywordtype">void</span>)
<a name="l00411"></a>00411 {
<a name="l00412"></a>00412     uint32_t       err_code;
<a name="l00413"></a>00413     <a class="code" href="structble__tps__init__t.html" title="TX Power Service init structure. This contains all options and data needed for initialization of the ...">ble_tps_init_t</a> tps_init_obj;
<a name="l00414"></a>00414 
<a name="l00415"></a>00415     memset(&amp;tps_init_obj, 0, <span class="keyword">sizeof</span>(tps_init_obj));
<a name="l00416"></a>00416     tps_init_obj.<a class="code" href="structble__tps__init__t.html#abd96f92499bb2a5fb13a1ba721c6feb1">initial_tx_power_level</a> = <a class="code" href="group__ble__sdk__app__proximity__main.html#ga5273cd1f329a5864a9c2bd28f65e9d54">TX_POWER_LEVEL</a>;
<a name="l00417"></a>00417     
<a name="l00418"></a>00418     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga99f7b13b3c63bcaffe700c9f28c3ee3f" title="Set sec_mode pointed to by ptr to require encryption, but no MITM protection.">BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM</a>(&amp;tps_init_obj.<a class="code" href="structble__tps__init__t.html#a258c687c7b07c69a197c16c542e83b1d">tps_attr_md</a>.<a class="code" href="structble__srv__security__mode__t.html#af0352a482ca2a1305ec5941bc4af0ec2">read_perm</a>);
<a name="l00419"></a>00419     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga1cf3822f8bb11e28931afbb9179665b7" title="Set sec_mode pointed to by ptr to have no access rights.">BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS</a>(&amp;tps_init_obj.<a class="code" href="structble__tps__init__t.html#a258c687c7b07c69a197c16c542e83b1d">tps_attr_md</a>.<a class="code" href="structble__srv__security__mode__t.html#a6060006e42afe1970aed0a8490f71445">write_perm</a>);
<a name="l00420"></a>00420 
<a name="l00421"></a>00421     err_code = <a class="code" href="group__ble__sdk__srv__tps.html#gadf50170201ca904944d8ba0ecb485ba7" title="Initialize the TX Power Service.">ble_tps_init</a>(&amp;<a class="code" href="group__ble__sdk__app__proximity__main.html#gafd5babfaabd7e4c921c4cc813fb3f31f">s_tps</a>, &amp;tps_init_obj);
<a name="l00422"></a>00422     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00423"></a>00423     {
<a name="l00424"></a>00424         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00425"></a>00425     }
<a name="l00426"></a>00426 }
<a name="l00427"></a>00427 
<a name="l00428"></a>00428 
<a name="l00431"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga6e6c548f4f38853a656d7a03a63a4e4d">00431</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__proximity__main.html#ga6e6c548f4f38853a656d7a03a63a4e4d" title="Initialize Immediate Alert Service.">ias_init</a>(<span class="keywordtype">void</span>)
<a name="l00432"></a>00432 {
<a name="l00433"></a>00433     uint32_t       err_code;
<a name="l00434"></a>00434     <a class="code" href="structble__ias__init__t.html" title="Immediate Alert Service init structure. This contains all options and data needed for initialization ...">ble_ias_init_t</a> ias_init_obj;
<a name="l00435"></a>00435 
<a name="l00436"></a>00436     memset(&amp;ias_init_obj, 0, <span class="keyword">sizeof</span>(ias_init_obj));
<a name="l00437"></a>00437     ias_init_obj.<a class="code" href="structble__ias__init__t.html#ab6cd7fc1e930717f3a8626add7f70701">evt_handler</a> = <a class="code" href="group__ble__sdk__app__proximity__main.html#ga943e77d327737757ea2bdf929e75349d" title="Immediate Alert event handler.">on_ias_evt</a>;
<a name="l00438"></a>00438     
<a name="l00439"></a>00439     err_code = <a class="code" href="group__ble__sdk__srv__ias.html#gaa1d939e0499a5e34f6c9752347f6b974" title="Initialize the Immediate Alert Service.">ble_ias_init</a>(&amp;<a class="code" href="group__ble__sdk__app__proximity__main.html#ga7ae2ab02279a8b58ff472c6d050bbe60">s_ias</a>, &amp;ias_init_obj);
<a name="l00440"></a>00440     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00441"></a>00441     {
<a name="l00442"></a>00442         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00443"></a>00443     }
<a name="l00444"></a>00444 }
<a name="l00445"></a>00445 
<a name="l00446"></a>00446 
<a name="l00449"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga6e9243342e5712bd6364de76dc42bfdc">00449</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__proximity__main.html#ga6e9243342e5712bd6364de76dc42bfdc" title="Initialize Link Loss Service.">lls_init</a>(<span class="keywordtype">void</span>)
<a name="l00450"></a>00450 {
<a name="l00451"></a>00451     uint32_t       err_code;
<a name="l00452"></a>00452     <a class="code" href="structble__lls__init__t.html" title="Link Loss Service init structure. This contains all options and data needed for initialization of the...">ble_lls_init_t</a> lls_init_obj;
<a name="l00453"></a>00453 
<a name="l00454"></a>00454     <span class="comment">// Initialize Link Loss Service</span>
<a name="l00455"></a>00455     memset(&amp;lls_init_obj, 0, <span class="keyword">sizeof</span>(lls_init_obj));
<a name="l00456"></a>00456     
<a name="l00457"></a>00457     lls_init_obj.<a class="code" href="structble__lls__init__t.html#ad638cfefb86a629f876a2bec3f6ef005">evt_handler</a>         = <a class="code" href="group__ble__sdk__app__proximity__main.html#ga038703ec77748ff3b1b0c88f21579c5c" title="Link Loss event handler.">on_lls_evt</a>;
<a name="l00458"></a>00458     lls_init_obj.<a class="code" href="structble__lls__init__t.html#a893a7b5845beb42d9e5b650fd012f7f1">error_handler</a>       = <a class="code" href="group__ble__sdk__app__proximity__main.html#ga54ab546c90d69e5fc9cfee653024ea53" title="Service error handler.">service_error_handler</a>;
<a name="l00459"></a>00459     lls_init_obj.<a class="code" href="structble__lls__init__t.html#a6cfd8720001bb376be2bcd9761923761">initial_alert_level</a> = <a class="code" href="group__ble__sdk__app__proximity__main.html#ga6c90d462c21d0b30c272f5cba8963836">INITIAL_LLS_ALERT_LEVEL</a>;
<a name="l00460"></a>00460     
<a name="l00461"></a>00461     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga99f7b13b3c63bcaffe700c9f28c3ee3f" title="Set sec_mode pointed to by ptr to require encryption, but no MITM protection.">BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM</a>(&amp;lls_init_obj.<a class="code" href="structble__lls__init__t.html#aaab7252a73b78834205cf4853e21faa7">lls_attr_md</a>.<a class="code" href="structble__srv__security__mode__t.html#af0352a482ca2a1305ec5941bc4af0ec2">read_perm</a>);
<a name="l00462"></a>00462     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga99f7b13b3c63bcaffe700c9f28c3ee3f" title="Set sec_mode pointed to by ptr to require encryption, but no MITM protection.">BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM</a>(&amp;lls_init_obj.<a class="code" href="structble__lls__init__t.html#aaab7252a73b78834205cf4853e21faa7">lls_attr_md</a>.<a class="code" href="structble__srv__security__mode__t.html#a6060006e42afe1970aed0a8490f71445">write_perm</a>);
<a name="l00463"></a>00463 
<a name="l00464"></a>00464     err_code = <a class="code" href="group__ble__sdk__srv__lls.html#ga7f1365b395cf05261b2f659dc3ed992b" title="Initialize the Link Loss Service.">ble_lls_init</a>(&amp;<a class="code" href="group__ble__sdk__app__proximity__main.html#gab81d1349f60eface9bdcf27d9ece74a5">s_lls</a>, &amp;lls_init_obj);
<a name="l00465"></a>00465     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00466"></a>00466     {
<a name="l00467"></a>00467         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00468"></a>00468     }
<a name="l00469"></a>00469 }
<a name="l00470"></a>00470 
<a name="l00471"></a>00471 
<a name="l00474"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga46507354f43dd16b32281f032e29d9c5">00474</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__proximity__main.html#ga46507354f43dd16b32281f032e29d9c5" title="Initialize Battery Service.">bas_init</a>(<span class="keywordtype">void</span>)
<a name="l00475"></a>00475 {
<a name="l00476"></a>00476     uint32_t       err_code;
<a name="l00477"></a>00477     <a class="code" href="structble__bas__init__t.html" title="Battery Service init structure. This contains all options and data needed for initialization of the s...">ble_bas_init_t</a> bas_init_obj;
<a name="l00478"></a>00478     
<a name="l00479"></a>00479     memset(&amp;bas_init_obj, 0, <span class="keyword">sizeof</span>(bas_init_obj));
<a name="l00480"></a>00480     
<a name="l00481"></a>00481     bas_init_obj.<a class="code" href="structble__bas__init__t.html#a3c25f96941dd8c1b92407ed2994691c6">evt_handler</a>          = NULL;
<a name="l00482"></a>00482     bas_init_obj.<a class="code" href="structble__bas__init__t.html#adbf298550acd37c0d6170e90504318ac">support_notification</a> = <span class="keyword">true</span>;
<a name="l00483"></a>00483     bas_init_obj.<a class="code" href="structble__bas__init__t.html#ac3ce984f1c066cfc0911e98fa1acdc8e">p_report_ref</a>         = NULL;
<a name="l00484"></a>00484     bas_init_obj.<a class="code" href="structble__bas__init__t.html#ae5e656df4b847b3a099792ae32676d16">initial_batt_level</a>   = 100;
<a name="l00485"></a>00485 
<a name="l00486"></a>00486     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga2abd1c711d49a4d4b1ab9bf27cafffbb" title="Set sec_mode pointed to by ptr to require no protection, open link.">BLE_GAP_CONN_SEC_MODE_SET_OPEN</a>(&amp;bas_init_obj.<a class="code" href="structble__bas__init__t.html#ada6a205c81f51d9aa2de33bbdea0bd26">battery_level_char_attr_md</a>.cccd_write_perm);
<a name="l00487"></a>00487     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga2abd1c711d49a4d4b1ab9bf27cafffbb" title="Set sec_mode pointed to by ptr to require no protection, open link.">BLE_GAP_CONN_SEC_MODE_SET_OPEN</a>(&amp;bas_init_obj.<a class="code" href="structble__bas__init__t.html#ada6a205c81f51d9aa2de33bbdea0bd26">battery_level_char_attr_md</a>.<a class="code" href="structble__srv__cccd__security__mode__t.html#af0352a482ca2a1305ec5941bc4af0ec2">read_perm</a>);
<a name="l00488"></a>00488     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga1cf3822f8bb11e28931afbb9179665b7" title="Set sec_mode pointed to by ptr to have no access rights.">BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS</a>(&amp;bas_init_obj.<a class="code" href="structble__bas__init__t.html#ada6a205c81f51d9aa2de33bbdea0bd26">battery_level_char_attr_md</a>.<a class="code" href="structble__srv__cccd__security__mode__t.html#a6060006e42afe1970aed0a8490f71445">write_perm</a>);
<a name="l00489"></a>00489 
<a name="l00490"></a>00490     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga2abd1c711d49a4d4b1ab9bf27cafffbb" title="Set sec_mode pointed to by ptr to require no protection, open link.">BLE_GAP_CONN_SEC_MODE_SET_OPEN</a>(&amp;bas_init_obj.<a class="code" href="structble__bas__init__t.html#a2c9724572f64316880f915bb78882de0">battery_level_report_read_perm</a>);
<a name="l00491"></a>00491     
<a name="l00492"></a>00492     err_code = <a class="code" href="group__ble__sdk__srv__bas.html#gacb8ac9205dcec39e216575c76261c807" title="Initialize the Battery Service.">ble_bas_init</a>(&amp;<a class="code" href="group__ble__sdk__app__proximity__main.html#gab22f840926bbada5a0ba32f2f7dc94b3">s_bas</a>, &amp;bas_init_obj);
<a name="l00493"></a>00493     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00494"></a>00494     {
<a name="l00495"></a>00495         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00496"></a>00496     }
<a name="l00497"></a>00497 }
<a name="l00498"></a>00498 
<a name="l00499"></a>00499 
<a name="l00502"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga5b27b40e18af00d43b92f57eaed0e9b2">00502</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__proximity__main.html#ga5b27b40e18af00d43b92f57eaed0e9b2" title="Initialize services that will be used by the application.">services_init</a>(<span class="keywordtype">void</span>)
<a name="l00503"></a>00503 {
<a name="l00504"></a>00504     <a class="code" href="group__ble__sdk__app__proximity__main.html#gab793003188ea0cfe80805f209cfe18f9" title="Initialize Tx Power Service.">tps_init</a>();
<a name="l00505"></a>00505     <a class="code" href="group__ble__sdk__app__proximity__main.html#ga6e6c548f4f38853a656d7a03a63a4e4d" title="Initialize Immediate Alert Service.">ias_init</a>();
<a name="l00506"></a>00506     <a class="code" href="group__ble__sdk__app__proximity__main.html#ga6e9243342e5712bd6364de76dc42bfdc" title="Initialize Link Loss Service.">lls_init</a>();
<a name="l00507"></a>00507     <a class="code" href="group__ble__sdk__app__proximity__main.html#ga46507354f43dd16b32281f032e29d9c5" title="Initialize Battery Service.">bas_init</a>();
<a name="l00508"></a>00508 }
<a name="l00509"></a>00509 
<a name="l00510"></a>00510 
<a name="l00513"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga6f75e3fe8d4ed6400f9429987dee0f3e">00513</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__proximity__main.html#ga6f75e3fe8d4ed6400f9429987dee0f3e" title="Initialize the battery sensor simulator.">sensor_sim_init</a>(<span class="keywordtype">void</span>)
<a name="l00514"></a>00514 {
<a name="l00515"></a>00515     <a class="code" href="group__ble__sdk__app__proximity__main.html#gaa752585d9b405d6e0c6fd392d7f64b59">s_battery_sim_cfg</a>.<a class="code" href="structble__sensorsim__cfg__t.html#a0de4531998c77245b8866f2ba909d0fa">min</a>          = <a class="code" href="group__ble__sdk__app__proximity__main.html#ga59eb06cba38be11278ebd2829e95bc26">MIN_BATTERY_LEVEL</a>;
<a name="l00516"></a>00516     <a class="code" href="group__ble__sdk__app__proximity__main.html#gaa752585d9b405d6e0c6fd392d7f64b59">s_battery_sim_cfg</a>.<a class="code" href="structble__sensorsim__cfg__t.html#a43e74ba18dc1a237d9f7737ce8df350e">max</a>          = <a class="code" href="group__ble__sdk__app__proximity__main.html#ga16896fb7a69ca90a4a4e341d5a888002">MAX_BATTERY_LEVEL</a>;
<a name="l00517"></a>00517     <a class="code" href="group__ble__sdk__app__proximity__main.html#gaa752585d9b405d6e0c6fd392d7f64b59">s_battery_sim_cfg</a>.<a class="code" href="structble__sensorsim__cfg__t.html#a4eed0a83fb9e9824223f835e2b7b3032">incr</a>         = <a class="code" href="group__ble__sdk__app__proximity__main.html#ga69eef02165834e4dabc5757b82dddbf1">BATTERY_LEVEL_INCREMENT</a>;
<a name="l00518"></a>00518     <a class="code" href="group__ble__sdk__app__proximity__main.html#gaa752585d9b405d6e0c6fd392d7f64b59">s_battery_sim_cfg</a>.<a class="code" href="structble__sensorsim__cfg__t.html#a91158ca4700058aaa6a54de96b67146a">start_at_max</a> = <span class="keyword">true</span>;
<a name="l00519"></a>00519     
<a name="l00520"></a>00520     <a class="code" href="group__ble__sdk__lib__sensorsim.html#ga87dbeaec725800b329897a89763da807" title="Initialize a triangular waveform sensor simulator.">ble_sensorsim_init</a>(&amp;<a class="code" href="group__ble__sdk__app__proximity__main.html#gaa51f5fc284e1b7e1570ab742fa9b63f3">s_battery_sim_state</a>, &amp;<a class="code" href="group__ble__sdk__app__proximity__main.html#gaa752585d9b405d6e0c6fd392d7f64b59">s_battery_sim_cfg</a>);
<a name="l00521"></a>00521 }
<a name="l00522"></a>00522 
<a name="l00523"></a>00523 
<a name="l00526"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga9f11118fb9ce22ad1afe20af6f89b131">00526</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__proximity__main.html#ga9f11118fb9ce22ad1afe20af6f89b131" title="Initialize security parameters.">sec_params_init</a>(<span class="keywordtype">void</span>)
<a name="l00527"></a>00527 {
<a name="l00528"></a>00528     <a class="code" href="group__ble__sdk__app__proximity__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a7f1ad43d3bf79b40bc39dbb5a6c3a5ae">timeout</a>      = <a class="code" href="group__ble__sdk__app__proximity__main.html#ga7c1fffb0f865552108560d4c63b32db1">SEC_PARAM_TIMEOUT</a>;
<a name="l00529"></a>00529     <a class="code" href="group__ble__sdk__app__proximity__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a3d9eee3a6a1d710b0e5d13b567675694">bond</a>         = <a class="code" href="group__ble__sdk__app__proximity__main.html#gacbf03a82593c273743a5a80a1119b851">SEC_PARAM_BOND</a>;
<a name="l00530"></a>00530     <a class="code" href="group__ble__sdk__app__proximity__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a808e5ec85cf1656a05a985386ba29276">mitm</a>         = <a class="code" href="group__ble__sdk__app__proximity__main.html#gab6831ebe113f8afe970326b7742b5947">SEC_PARAM_MITM</a>;
<a name="l00531"></a>00531     <a class="code" href="group__ble__sdk__app__proximity__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a81d248b843331e8798478feecf4f4c92">io_caps</a>      = <a class="code" href="group__ble__sdk__app__proximity__main.html#ga42df85b3a4083cdc614d9111d580d98f">SEC_PARAM_IO_CAPABILITIES</a>;
<a name="l00532"></a>00532     <a class="code" href="group__ble__sdk__app__proximity__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a01318f39f3b3471bd44bf2f322331788">oob</a>          = <a class="code" href="group__ble__sdk__app__proximity__main.html#gaee13a0d0077f423fa0edd74e17fb6b88">SEC_PARAM_OOB</a>;  
<a name="l00533"></a>00533     <a class="code" href="group__ble__sdk__app__proximity__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a66c3e526aae4ca7f3212ae207225b0a2">min_key_size</a> = <a class="code" href="group__ble__sdk__app__proximity__main.html#ga6b7b2e2f67fbf790f55b46f8f5e24ad5">SEC_PARAM_MIN_KEY_SIZE</a>;
<a name="l00534"></a>00534     <a class="code" href="group__ble__sdk__app__proximity__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a43d814618fbf7f63a318966dd84746c2">max_key_size</a> = <a class="code" href="group__ble__sdk__app__proximity__main.html#gaf2cd1595de153ea1d6d843619a1a7707">SEC_PARAM_MAX_KEY_SIZE</a>;
<a name="l00535"></a>00535 }
<a name="l00536"></a>00536 
<a name="l00537"></a>00537 
<a name="l00542"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga4538ed130db3bf7fc68b76a4d9e032fa">00542</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__proximity__main.html#ga4538ed130db3bf7fc68b76a4d9e032fa" title="Connection Parameters module error handler.">conn_params_error_handler</a>(uint32_t nrf_error)
<a name="l00543"></a>00543 {
<a name="l00544"></a>00544     <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00545"></a>00545 }
<a name="l00546"></a>00546 
<a name="l00547"></a>00547 
<a name="l00550"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#gaf61b6c1c47f5c96b169ff81c345d7849">00550</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__proximity__main.html#gaf61b6c1c47f5c96b169ff81c345d7849" title="Initialize the Connection Parameters module.">conn_params_init</a>(<span class="keywordtype">void</span>)
<a name="l00551"></a>00551 {
<a name="l00552"></a>00552     uint32_t               err_code;
<a name="l00553"></a>00553     <a class="code" href="structble__conn__params__init__t.html" title="Connection Parameters Module init structure. This contains all options and data needed for initializa...">ble_conn_params_init_t</a> cp_init;
<a name="l00554"></a>00554     
<a name="l00555"></a>00555     memset(&amp;cp_init, 0, <span class="keyword">sizeof</span>(cp_init));
<a name="l00556"></a>00556 
<a name="l00557"></a>00557     cp_init.<a class="code" href="structble__conn__params__init__t.html#ab211e40857ee8019c8fd5eabfcc12ce7">p_conn_params</a>                  = NULL;
<a name="l00558"></a>00558     cp_init.<a class="code" href="structble__conn__params__init__t.html#a915702f42f9a0316745403644d385f22">first_conn_params_update_delay</a> = <a class="code" href="group__ble__sdk__app__proximity__main.html#ga7204f7a367e8f1ac53ef62c4ad220efc">FIRST_CONN_PARAMS_UPDATE_DELAY</a>;
<a name="l00559"></a>00559     cp_init.<a class="code" href="structble__conn__params__init__t.html#a9bcd0621fbb5f4554f1fafd0b15dc61b">next_conn_params_update_delay</a>  = <a class="code" href="group__ble__sdk__app__proximity__main.html#gadf85796ef07632ed27e0bce9509d9245">NEXT_CONN_PARAMS_UPDATE_DELAY</a>;
<a name="l00560"></a>00560     cp_init.<a class="code" href="structble__conn__params__init__t.html#ab3c0944561623d4a8da622b18867aafb">max_conn_params_update_count</a>   = <a class="code" href="group__ble__sdk__app__proximity__main.html#ga34db81384bfbef23dedbef9bc6dfe46c">MAX_CONN_PARAMS_UPDATE_COUNT</a>;
<a name="l00561"></a>00561     cp_init.<a class="code" href="structble__conn__params__init__t.html#a6f0b0ef22161b61ba5cc0a7fd3ddedd9">start_on_notify_cccd_handle</a>    = <a class="code" href="group___b_l_e___g_a_t_t_s.html#gaa16a29908fc63343706f56913be51ec1" title="Invalid Attribute Handle.">BLE_GATTS_HANDLE_INVALID</a>;
<a name="l00562"></a>00562     cp_init.<a class="code" href="structble__conn__params__init__t.html#a7a3f3aac03305ef8012ade05399b5449">disconnect_on_fail</a>             = <span class="keyword">true</span>;
<a name="l00563"></a>00563     cp_init.<a class="code" href="structble__conn__params__init__t.html#af6344191be6d1f66ec79d6086def25f1">evt_handler</a>                    = NULL;
<a name="l00564"></a>00564     cp_init.<a class="code" href="structble__conn__params__init__t.html#a893a7b5845beb42d9e5b650fd012f7f1">error_handler</a>                  = <a class="code" href="group__ble__sdk__app__proximity__main.html#ga4538ed130db3bf7fc68b76a4d9e032fa" title="Connection Parameters module error handler.">conn_params_error_handler</a>;
<a name="l00565"></a>00565     
<a name="l00566"></a>00566     err_code = <a class="code" href="group__ble__sdk__lib__conn__params.html#gacd9789a0a4c90cfea2ba2656f6408080" title="Initialize the Connection Parameters module.">ble_conn_params_init</a>(&amp;cp_init);
<a name="l00567"></a>00567     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00568"></a>00568     {
<a name="l00569"></a>00569         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00570"></a>00570     }
<a name="l00571"></a>00571 }
<a name="l00572"></a>00572 
<a name="l00573"></a>00573 
<a name="l00578"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga4a4936c4f229d7988be372cd588561b0">00578</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__proximity__main.html#ga4a4936c4f229d7988be372cd588561b0" title="Signals alert event from Immediate Alert or Link Loss services.">alert_signal</a>(uint8_t alert_level)
<a name="l00579"></a>00579 {
<a name="l00580"></a>00580     <span class="keywordflow">switch</span> (alert_level)
<a name="l00581"></a>00581     {
<a name="l00582"></a>00582         <span class="keywordflow">case</span> <a class="code" href="group___a_l_e_r_t___l_e_v_e_l___v_a_l_u_e_s.html#ga19af58d002f35b548719d7043562cee7">BLE_CHAR_ALERT_LEVEL_NO_ALERT</a>:
<a name="l00583"></a>00583             <a class="code" href="group__nrf__gpio.html#gaf3de3729249d55592c86ecfa97fb9347" title="Clear GPIO pin.">nrf_gpio_pin_clear</a>(<a class="code" href="group__ble__sdk__app__proximity__main.html#gabab92753edef69fc4821618765ae1541">ALERT_LEVEL_MILD_LED_PIN_NO</a>);
<a name="l00584"></a>00584             <a class="code" href="group__nrf__gpio.html#gaf3de3729249d55592c86ecfa97fb9347" title="Clear GPIO pin.">nrf_gpio_pin_clear</a>(<a class="code" href="group__ble__sdk__app__proximity__main.html#ga40c245aa7d948f577a38078b5fc7fa84">ALERT_LEVEL_HIGH_LED_PIN_NO</a>);
<a name="l00585"></a>00585             <span class="keywordflow">break</span>;
<a name="l00586"></a>00586 
<a name="l00587"></a>00587         <span class="keywordflow">case</span> <a class="code" href="group___a_l_e_r_t___l_e_v_e_l___v_a_l_u_e_s.html#gaf4fb46aeec8acd50f37f0e6277e45cee">BLE_CHAR_ALERT_LEVEL_MILD_ALERT</a>:
<a name="l00588"></a>00588             <a class="code" href="group__nrf__gpio.html#gacaf7e8e242a47f7b635bbeca5c5934a3" title="Set GPIO pin.">nrf_gpio_pin_set</a>(<a class="code" href="group__ble__sdk__app__proximity__main.html#gabab92753edef69fc4821618765ae1541">ALERT_LEVEL_MILD_LED_PIN_NO</a>);
<a name="l00589"></a>00589             <a class="code" href="group__nrf__gpio.html#gaf3de3729249d55592c86ecfa97fb9347" title="Clear GPIO pin.">nrf_gpio_pin_clear</a>(<a class="code" href="group__ble__sdk__app__proximity__main.html#ga40c245aa7d948f577a38078b5fc7fa84">ALERT_LEVEL_HIGH_LED_PIN_NO</a>);
<a name="l00590"></a>00590             <span class="keywordflow">break</span>;
<a name="l00591"></a>00591 
<a name="l00592"></a>00592         <span class="keywordflow">case</span> <a class="code" href="group___a_l_e_r_t___l_e_v_e_l___v_a_l_u_e_s.html#ga9fc865fa1b7f643d40c5e43dc81c0556">BLE_CHAR_ALERT_LEVEL_HIGH_ALERT</a>:
<a name="l00593"></a>00593             <a class="code" href="group__nrf__gpio.html#gaf3de3729249d55592c86ecfa97fb9347" title="Clear GPIO pin.">nrf_gpio_pin_clear</a>(<a class="code" href="group__ble__sdk__app__proximity__main.html#gabab92753edef69fc4821618765ae1541">ALERT_LEVEL_MILD_LED_PIN_NO</a>);
<a name="l00594"></a>00594             <a class="code" href="group__nrf__gpio.html#gacaf7e8e242a47f7b635bbeca5c5934a3" title="Set GPIO pin.">nrf_gpio_pin_set</a>(<a class="code" href="group__ble__sdk__app__proximity__main.html#ga40c245aa7d948f577a38078b5fc7fa84">ALERT_LEVEL_HIGH_LED_PIN_NO</a>);
<a name="l00595"></a>00595             <span class="keywordflow">break</span>;
<a name="l00596"></a>00596             
<a name="l00597"></a>00597         <span class="keywordflow">default</span>:
<a name="l00598"></a>00598             <span class="keywordflow">break</span>;
<a name="l00599"></a>00599     }
<a name="l00600"></a>00600 }
<a name="l00601"></a>00601 
<a name="l00602"></a>00602 
<a name="l00611"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga943e77d327737757ea2bdf929e75349d">00611</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__proximity__main.html#ga943e77d327737757ea2bdf929e75349d" title="Immediate Alert event handler.">on_ias_evt</a>(<a class="code" href="structble__ias__s.html" title="Immediate Alert Service structure. This contains various status information for the service...">ble_ias_t</a> * p_ias, <a class="code" href="structble__ias__evt__t.html" title="Immediate Alert Service event.">ble_ias_evt_t</a> * p_evt)
<a name="l00612"></a>00612 {
<a name="l00613"></a>00613     <span class="keywordflow">switch</span> (p_evt-&gt;<a class="code" href="structble__ias__evt__t.html#a4ed45327ae86f5f95bfe514bd5c04a2e">evt_type</a>)
<a name="l00614"></a>00614     {
<a name="l00615"></a>00615         <span class="keywordflow">case</span> <a class="code" href="group__ble__sdk__srv__ias.html#ggaa55445ca6b845393a2dc353e0afa38ecaf04e8963239be8fd6c09d876f88db8ff">BLE_IAS_EVT_ALERT_LEVEL_UPDATED</a>:
<a name="l00616"></a>00616             <a class="code" href="group__ble__sdk__app__proximity__main.html#ga4a4936c4f229d7988be372cd588561b0" title="Signals alert event from Immediate Alert or Link Loss services.">alert_signal</a>(p_evt-&gt;params.<a class="code" href="structble__ias__evt__t.html#ad8d1cb33bad56df390f98280b3bba826">alert_level</a>);
<a name="l00617"></a>00617             <span class="keywordflow">break</span>;
<a name="l00618"></a>00618             
<a name="l00619"></a>00619         <span class="keywordflow">default</span>:
<a name="l00620"></a>00620             <span class="keywordflow">break</span>;
<a name="l00621"></a>00621     }
<a name="l00622"></a>00622 }
<a name="l00623"></a>00623 
<a name="l00624"></a>00624 
<a name="l00633"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga038703ec77748ff3b1b0c88f21579c5c">00633</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__proximity__main.html#ga038703ec77748ff3b1b0c88f21579c5c" title="Link Loss event handler.">on_lls_evt</a>(<a class="code" href="structble__lls__s.html" title="Link Loss Service structure. This contains various status information for the service.">ble_lls_t</a> * p_lls, <a class="code" href="structble__lls__evt__t.html" title="Link Loss Service event.">ble_lls_evt_t</a> * p_evt)
<a name="l00634"></a>00634 {
<a name="l00635"></a>00635     <span class="keywordflow">switch</span> (p_evt-&gt;<a class="code" href="structble__lls__evt__t.html#a4ddbb835a206dca2495c6340a3d64cb4">evt_type</a>)
<a name="l00636"></a>00636     {
<a name="l00637"></a>00637         <span class="keywordflow">case</span> <a class="code" href="group__ble__sdk__srv__lls.html#gga94331ff0a90e8f8b61dcf230e1760ccfa2b53ad90d2e6afd7294ca052768d7438">BLE_LLS_EVT_LINK_LOSS_ALERT</a>:
<a name="l00638"></a>00638             <a class="code" href="group__ble__sdk__app__proximity__main.html#ga4a4936c4f229d7988be372cd588561b0" title="Signals alert event from Immediate Alert or Link Loss services.">alert_signal</a>(p_evt-&gt;params.<a class="code" href="structble__lls__evt__t.html#ad8d1cb33bad56df390f98280b3bba826">alert_level</a>);
<a name="l00639"></a>00639             <span class="keywordflow">break</span>;
<a name="l00640"></a>00640             
<a name="l00641"></a>00641         <span class="keywordflow">default</span>:
<a name="l00642"></a>00642             <span class="keywordflow">break</span>;
<a name="l00643"></a>00643     }
<a name="l00644"></a>00644 }
<a name="l00645"></a>00645 
<a name="l00646"></a>00646 
<a name="l00651"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#gad083cb3569230d7ecbf2d01ef2a2c1d9">00651</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__proximity__main.html#gad083cb3569230d7ecbf2d01ef2a2c1d9" title="Application&#39;s BLE Stack event handler.">on_ble_evt</a>(<a class="code" href="structble__evt__t.html" title="Common BLE Event type, wrapping the module specific event reports.">ble_evt_t</a> * p_ble_evt)
<a name="l00652"></a>00652 {
<a name="l00653"></a>00653     uint32_t        err_code = <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>;
<a name="l00654"></a>00654     <span class="keyword">static</span> uint16_t <a class="code" href="group__ble__sdk__app__hrs__main.html#gaaf76d22968f9f320aa5005a25f654320">s_conn_handle</a> = <a class="code" href="group___b_l_e___c_o_n_n___h_a_n_d_l_e_s.html#gacf227b9b101dbcf08eccbbaba54e48f5">BLE_CONN_HANDLE_INVALID</a>;
<a name="l00655"></a>00655     
<a name="l00656"></a>00656     <span class="keywordflow">switch</span> (p_ble_evt-&gt;<a class="code" href="structble__evt__t.html#a50f33abba5627a26728ba30fffd9880a">header</a>.<a class="code" href="structble__evt__hdr__t.html#a826314e7ea25d4267621899efe6859f9">evt_id</a>)
<a name="l00657"></a>00657     {
<a name="l00658"></a>00658         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035daa0b4789724d202a13a5e7eab85c52957">BLE_GAP_EVT_CONNECTED</a>:
<a name="l00659"></a>00659             <a class="code" href="group__nrf__gpio.html#gacaf7e8e242a47f7b635bbeca5c5934a3" title="Set GPIO pin.">nrf_gpio_pin_set</a>(CONNECTED_LED_PIN_NO);
<a name="l00660"></a>00660             <a class="code" href="group__nrf__gpio.html#gaf3de3729249d55592c86ecfa97fb9347" title="Clear GPIO pin.">nrf_gpio_pin_clear</a>(ADVERTISING_LED_PIN_NO);
<a name="l00661"></a>00661             <a class="code" href="group__nrf__gpio.html#gaf3de3729249d55592c86ecfa97fb9347" title="Clear GPIO pin.">nrf_gpio_pin_clear</a>(<a class="code" href="group__ble__sdk__app__proximity__main.html#ga70b0e83bb09a339ead4165071e8121ae">ADV_INTERVAL_SLOW_LED_PIN_NO</a>);
<a name="l00662"></a>00662             <a class="code" href="group__app__timer.html#ga4112ddbc75deb5c4d5db7c8afb1f5d8a" title="Stops the specified timer.">app_timer_stop</a>(APP_TIMER_ADV_INTERVAL_CHANGE);
<a name="l00663"></a>00663             <a class="code" href="group__ble__sdk__app__proximity__main.html#ga76b78faf2670ecd8a7deea500be9d971">s_is_advertising</a> = <span class="keyword">false</span>;
<a name="l00664"></a>00664             s_conn_handle = p_ble_evt-&gt;evt.<a class="code" href="structble__evt__t.html#a91857ca158f0c4e43f610068772c7d3d">gatts_evt</a>.<a class="code" href="structble__gatts__evt__t.html#a0d5ffe38d68e48d81e61fc6a4999ae68">conn_handle</a>;
<a name="l00665"></a>00665             err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga3dda6bbc1387aecee1f9dde1e78f197d" title="Initiate GAP Authentication procedure.">ble_gap_authenticate</a>(s_conn_handle, &amp;<a class="code" href="group__ble__sdk__app__proximity__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>);
<a name="l00666"></a>00666             <span class="keywordflow">break</span>;
<a name="l00667"></a>00667             
<a name="l00668"></a>00668         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035da057001bbd6ea9e615f19ef93cc0831ee">BLE_GAP_EVT_DISCONNECTED</a>:
<a name="l00669"></a>00669             <a class="code" href="group__nrf__gpio.html#gaf3de3729249d55592c86ecfa97fb9347" title="Clear GPIO pin.">nrf_gpio_pin_clear</a>(CONNECTED_LED_PIN_NO);
<a name="l00670"></a>00670             s_conn_handle = <a class="code" href="group___b_l_e___c_o_n_n___h_a_n_d_l_e_s.html#gacf227b9b101dbcf08eccbbaba54e48f5">BLE_CONN_HANDLE_INVALID</a>;
<a name="l00671"></a>00671             <a class="code" href="group__ble__sdk__app__proximity__main.html#ga236a1a602913d6780d797d929507873e" title="Start advertising.">advertising_start</a>(<span class="keyword">true</span>);
<a name="l00672"></a>00672             <span class="keywordflow">break</span>;
<a name="l00673"></a>00673             
<a name="l00674"></a>00674         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035da6c5eefbcfabbc1ce4a8bcbf550c285ae">BLE_GAP_EVT_SEC_PARAMS_REQUEST</a>:
<a name="l00675"></a>00675             err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga5339c2562371354a0e3752b86214b92a" title="Reply with GAP security parameters.">ble_gap_sec_params_reply</a>(s_conn_handle, 
<a name="l00676"></a>00676                                                 <a class="code" href="group___b_l_e___g_a_p___s_e_c___s_t_a_t_u_s.html#gaa0334dea24e449e5c28c88bbe8a1d00f">BLE_GAP_SEC_STATUS_SUCCESS</a>, 
<a name="l00677"></a>00677                                                 &amp;<a class="code" href="group__ble__sdk__app__proximity__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>);
<a name="l00678"></a>00678             <span class="keywordflow">break</span>;
<a name="l00679"></a>00679 
<a name="l00680"></a>00680         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035da57e5d1061d9b3d1500fb3556a3fb8847">BLE_GAP_EVT_TIMEOUT</a>:
<a name="l00681"></a>00681             <span class="keywordflow">if</span> (p_ble_evt-&gt;evt.<a class="code" href="structble__evt__t.html#a2fd98f8868b9aea30d35bf71d41d646a">gap_evt</a>.params.<a class="code" href="structble__gap__evt__t.html#a17e289da592e731cde1451c2d5f3f24a">timeout</a>.<a class="code" href="structble__gap__evt__timeout__t.html#af5eca485cd2b34522478907d4c8f5bc6">src</a> == <a class="code" href="group___b_l_e___g_a_p___t_i_m_e_o_u_t___t_y_p_e_s.html#gafee7b7095fb21ed922c6719cc1c2d23f">BLE_GAP_TIMEOUT_TYPE_ADVERTISEMENT</a>)
<a name="l00682"></a>00682             { 
<a name="l00683"></a>00683                 <a class="code" href="group__nrf__gpio.html#gaf3de3729249d55592c86ecfa97fb9347" title="Clear GPIO pin.">nrf_gpio_pin_clear</a>(ADVERTISING_LED_PIN_NO);
<a name="l00684"></a>00684                 <a class="code" href="group__nrf__gpio.html#gaf3de3729249d55592c86ecfa97fb9347" title="Clear GPIO pin.">nrf_gpio_pin_clear</a>(<a class="code" href="group__ble__sdk__app__proximity__main.html#ga70b0e83bb09a339ead4165071e8121ae">ADV_INTERVAL_SLOW_LED_PIN_NO</a>);
<a name="l00685"></a>00685                 
<a name="l00686"></a>00686                 err_code = <a class="code" href="group__ble__sdk__lib__bond__manager.html#ga2f338b201c43be781a0194a97a243318" title="Function to be called before going to system off, in order to save all bonded masters in flash memory...">ble_bondmngr_on_goto_system_off</a>();
<a name="l00687"></a>00687                 <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00688"></a>00688                 {
<a name="l00689"></a>00689                     <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00690"></a>00690                 }
<a name="l00691"></a>00691 
<a name="l00692"></a>00692                 <span class="comment">// Go to system-off mode (this function will not return; wakeup will cause a reset)</span>
<a name="l00693"></a>00693                 err_code = <a class="code" href="group__nrf__soc__api.html#ga302701614c7bb1c9fc01dafec2bb04fb" title="Puts the chip in System OFF mode.">nrf_power_system_off</a>();    
<a name="l00694"></a>00694             }
<a name="l00695"></a>00695             <span class="keywordflow">break</span>;
<a name="l00696"></a>00696             
<a name="l00697"></a>00697         <span class="keywordflow">default</span>:
<a name="l00698"></a>00698             <span class="keywordflow">break</span>;
<a name="l00699"></a>00699     }
<a name="l00700"></a>00700 
<a name="l00701"></a>00701     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00702"></a>00702     {
<a name="l00703"></a>00703         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00704"></a>00704     }
<a name="l00705"></a>00705 }
<a name="l00706"></a>00706 
<a name="l00707"></a>00707 
<a name="l00715"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga2b08d6ccb6e7f4588d2ac843d4494c0e">00715</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__proximity__main.html#ga2b08d6ccb6e7f4588d2ac843d4494c0e" title="Dispatches a BLE stack event to all modules with a BLE stack event handler.">ble_evt_dispatch</a>(<a class="code" href="structble__evt__t.html" title="Common BLE Event type, wrapping the module specific event reports.">ble_evt_t</a> * p_ble_evt)
<a name="l00716"></a>00716 {
<a name="l00717"></a>00717     uint32_t err_code;
<a name="l00718"></a>00718     
<a name="l00719"></a>00719     err_code = <a class="code" href="group__ble__sdk__lib__bond__manager.html#ga0602a76664be6f6f19997368d9cf8860" title="Handles all events from the BLE stack that are of interest to this module.">ble_bondmngr_on_ble_evt</a>(p_ble_evt);
<a name="l00720"></a>00720     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00721"></a>00721     {
<a name="l00722"></a>00722         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00723"></a>00723     }
<a name="l00724"></a>00724 
<a name="l00725"></a>00725     <a class="code" href="group__ble__sdk__lib__conn__params.html#gadef0873bee110db3da8b77f801177871" title="BLE stack event handler.">ble_conn_params_on_ble_evt</a>(p_ble_evt);
<a name="l00726"></a>00726     <a class="code" href="group__ble__sdk__srv__ias.html#ga7aceea1ccf7fa036d066a08e19fe1504" title="Immediate Alert Service BLE stack event handler.">ble_ias_on_ble_evt</a>(&amp;<a class="code" href="group__ble__sdk__app__proximity__main.html#ga7ae2ab02279a8b58ff472c6d050bbe60">s_ias</a>, p_ble_evt);
<a name="l00727"></a>00727     <a class="code" href="group__ble__sdk__srv__lls.html#ga8016405e451656f510b244e4cbe09653" title="Link Loss Service BLE stack event handler.">ble_lls_on_ble_evt</a>(&amp;<a class="code" href="group__ble__sdk__app__proximity__main.html#gab81d1349f60eface9bdcf27d9ece74a5">s_lls</a>, p_ble_evt);
<a name="l00728"></a>00728     <a class="code" href="group__ble__sdk__srv__bas.html#ga01b70d77540660d7e312121d9f1d3b3a" title="Battery Service BLE stack event handler.">ble_bas_on_ble_evt</a>(&amp;<a class="code" href="group__ble__sdk__app__proximity__main.html#gab22f840926bbada5a0ba32f2f7dc94b3">s_bas</a>, p_ble_evt);
<a name="l00729"></a>00729     <a class="code" href="group__ble__sdk__app__proximity__main.html#gad083cb3569230d7ecbf2d01ef2a2c1d9" title="Application&#39;s BLE Stack event handler.">on_ble_evt</a>(p_ble_evt);
<a name="l00730"></a>00730 }
<a name="l00731"></a>00731 
<a name="l00732"></a>00732 
<a name="l00737"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#gaa06a7a39e83ec4cf3553f4ed6ba6323a">00737</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__proximity__main.html#gaa06a7a39e83ec4cf3553f4ed6ba6323a" title="BLE stack initialization.">ble_stack_init</a>(<span class="keywordtype">void</span>)
<a name="l00738"></a>00738 {
<a name="l00739"></a>00739     uint32_t err_code = <a class="code" href="group__ble__stack__handler.html#gada9282a45a226bbe8544995b2fbf22dd" title="Initialize stack handler module.">ble_stack_handler_init</a>(<a class="code" href="group__nrf__sdm__api.html#ggaaf8fd5f0e57d456151c951e0f3715fc4a1c5e9917211a50eac336a3fd2e467756">NRF_CLOCK_LFCLKSRC_XTAL_20_PPM</a>, <a class="code" href="group__ble__sdk__app__proximity__main.html#ga2b08d6ccb6e7f4588d2ac843d4494c0e" title="Dispatches a BLE stack event to all modules with a BLE stack event handler.">ble_evt_dispatch</a>);
<a name="l00740"></a>00740     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00741"></a>00741     {
<a name="l00742"></a>00742         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00743"></a>00743     }
<a name="l00744"></a>00744 }
<a name="l00745"></a>00745 
<a name="l00746"></a>00746 
<a name="l00749"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga8bc84b266765b8c76cd93a328824c07d">00749</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__proximity__main.html#ga8bc84b266765b8c76cd93a328824c07d" title="Bond Manager initialization.">bond_manager_init</a>(<span class="keywordtype">void</span>)
<a name="l00750"></a>00750 {
<a name="l00751"></a>00751     uint32_t err_code;
<a name="l00752"></a>00752 
<a name="l00753"></a>00753     <span class="comment">// Clear all bonded masters if the &quot;non-connectable advertisement start&quot; button is pushed</span>
<a name="l00754"></a>00754     <span class="keywordflow">if</span> (<a class="code" href="group__ble__sdk__app__proximity__main.html#ga8014b2b4745214caa69c5fddd0401388" title="Read the state of the input pin.">gpio_pin_read</a>(NRF6310_BUTTON_1) == 0)
<a name="l00755"></a>00755     {
<a name="l00756"></a>00756         <a class="code" href="group__ble__sdk__lib__bond__manager.html#ga8e2aacd9f59e03d60b8db1ee0819c296" title="Delete the bonded master database from flash.">ble_bondmngr_master_delete</a>();
<a name="l00757"></a>00757     }
<a name="l00758"></a>00758     
<a name="l00759"></a>00759     <span class="comment">// Initialize the Bond Manager</span>
<a name="l00760"></a>00760     err_code = <a class="code" href="group__ble__sdk__lib__bond__manager.html#ga3996361c2235fe463273d331b8ea8678" title="Initializes the Bond Manager.">ble_bondmngr_init</a>();
<a name="l00761"></a>00761     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00762"></a>00762     {
<a name="l00763"></a>00763         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00764"></a>00764     }
<a name="l00765"></a>00765 }
<a name="l00766"></a>00766 
<a name="l00767"></a>00767 
<a name="l00770"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga3adda2642702fdb99b08992c39494000">00770</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__proximity__main.html#ga3adda2642702fdb99b08992c39494000" title="Power manager.">power_manage</a>(<span class="keywordtype">void</span>)
<a name="l00771"></a>00771 {
<a name="l00772"></a>00772     uint32_t err_code = <a class="code" href="group__nrf__soc__api.html#ga2aae5f388f1b6179058c62e2fb05a547" title="Waits for an application event.">nrf_wait_for_app_event</a>();
<a name="l00773"></a>00773     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00774"></a>00774     {
<a name="l00775"></a>00775         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00776"></a>00776     }
<a name="l00777"></a>00777 }
<a name="l00778"></a>00778 
<a name="l00779"></a>00779 
<a name="l00782"></a><a class="code" href="group__ble__sdk__app__proximity__main.html#ga840291bc02cba5474a4cb46a9b9566fe">00782</a> <span class="keywordtype">int</span> <a class="code" href="group__ble__sdk__app__gzll__main.html#ga840291bc02cba5474a4cb46a9b9566fe" title="Application main function.">main</a>(<span class="keywordtype">void</span>)
<a name="l00783"></a>00783 {
<a name="l00784"></a>00784     <span class="comment">// Initialize</span>
<a name="l00785"></a>00785     <a class="code" href="group__ble__sdk__app__gzll__ui.html#ga67cfc3137a465e560792490e81365254" title="LEDs initialization.">leds_init</a>();
<a name="l00786"></a>00786     <a class="code" href="group__ble__sdk__app__gzll__ui.html#gacef6dd444cb6560da652897ee43ab306" title="Initialize GPIOTE module for detecting buttons.">buttons_init</a>();
<a name="l00787"></a>00787     <a class="code" href="group__ble__sdk__app__proximity__main.html#ga8bc84b266765b8c76cd93a328824c07d" title="Bond Manager initialization.">bond_manager_init</a>();
<a name="l00788"></a>00788     <a class="code" href="group__ble__sdk__app__proximity__main.html#gaa06a7a39e83ec4cf3553f4ed6ba6323a" title="BLE stack initialization.">ble_stack_init</a>();
<a name="l00789"></a>00789     <a class="code" href="group__ble__sdk__app__proximity__main.html#ga09658aaa0774820d8f25249d551bc283" title="Timer initialization.">timers_init</a>();
<a name="l00790"></a>00790     <a class="code" href="group__ble__sdk__app__proximity__main.html#ga1004973353f351806e42896c491a5ab2" title="GAP initialization.">gap_params_init</a>();
<a name="l00791"></a>00791     <a class="code" href="group__ble__sdk__app__proximity__main.html#ga935c9624de0709fe228dbefa4b54de48" title="Advertising functionality initialization.">advertising_init</a>();
<a name="l00792"></a>00792     <a class="code" href="group__ble__sdk__app__proximity__main.html#ga5b27b40e18af00d43b92f57eaed0e9b2" title="Initialize services that will be used by the application.">services_init</a>();
<a name="l00793"></a>00793     <a class="code" href="group__ble__sdk__app__proximity__main.html#ga6f75e3fe8d4ed6400f9429987dee0f3e" title="Initialize the battery sensor simulator.">sensor_sim_init</a>();
<a name="l00794"></a>00794     <a class="code" href="group__ble__sdk__app__proximity__main.html#gaf61b6c1c47f5c96b169ff81c345d7849" title="Initialize the Connection Parameters module.">conn_params_init</a>();
<a name="l00795"></a>00795     <a class="code" href="group__ble__sdk__app__proximity__main.html#ga9f11118fb9ce22ad1afe20af6f89b131" title="Initialize security parameters.">sec_params_init</a>();
<a name="l00796"></a>00796     <a class="code" href="group__ble__sdk__app__proximity__main.html#ga236a1a602913d6780d797d929507873e" title="Start advertising.">advertising_start</a>(<span class="keyword">true</span>);
<a name="l00797"></a>00797     
<a name="l00798"></a>00798     <span class="comment">// Enter main loop</span>
<a name="l00799"></a>00799     <span class="keywordflow">for</span> (;;)
<a name="l00800"></a>00800     {
<a name="l00801"></a>00801         <a class="code" href="group__ble__sdk__app__proximity__main.html#ga3adda2642702fdb99b08992c39494000" title="Power manager.">power_manage</a>();
<a name="l00802"></a>00802     }
<a name="l00803"></a>00803 }
<a name="l00804"></a>00804 
</pre></div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="nrf6310__nrf2752_2ble_2ble__app__proximity_2main_8c.html">main.c</a>      </li>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>


    <li class="footer">
      Copyright &copy 2006-2011 <a href="http://www.nordicsemi.no" style="text-decoration:none">Nordic Semiconductor</a>.
      All Rights Reserved.
      <a href="disclaimer.html">Disclaimer</a>
    </li>
   </ul>
 </div>


</body>
</html>
